// 1748. 唯一元素的和
/**
 * @param {number[]} nums
 * @return {number}
 */
// 记录出现次数
var sumOfUnique = function (nums) {
    const map = new Map()
    nums.forEach(num => {
        map.set(num, map.get(num) + 1 || 1)
    })
    let result = 0
    for (const [key, val] of map) {
        if (val == 1) {
            result += key
        }
    }
    return result
};
// 记录每个元素的状态 + 一次遍历
var sumOfUnique = function (nums) {
    let ans = 0
    const state = new Map()
    for (const num of nums) {
        if (!state.has(num)) {
            ans += num
            state.set(num, 1)
        } else if (state.get(num) === 1) {
            ans -= num
            state.set(num, 2)
        }
    }
    return ans
}
sumOfUnique([1, 2, 3, 2])